import Vue from 'vue';
import store from './store';
import App from './App';
import Loading from '@/components/Loading';
import Skeleton from '@/components/Skeleton';

import Json from './Json'; //测试用数据
import http from './http';
// #ifdef H5
import './utils/external';
// #endif
// #ifdef MP-WEIXIN
import './utils/updateVer';
// #endif

/**
 * 在Vue实例挂载几个常用的函数
 */
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
  //统一提示方便全局修改
  if (Boolean(title) === false) {
    return;
  }
  uni.showToast({
    title,
    duration,
    mask,
    icon
  });
};

const json = type => {
  //模拟异步请求数据
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(Json[type]);
    }, 500);
  });
};

Vue.config.productionTip = false;
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = { msg, json, data: Json };
Vue.prototype.$toast = msg;
Vue.prototype.$http = http;
Vue.component('skeleton', Skeleton);

App.mpType = 'app';

const app = new Vue({
  store,
  ...App
});
app.$mount();

// 挂载Loading组件
// #ifdef H5
const LoadingConstructor = Vue.extend(Loading);
const instance = new LoadingConstructor();
instance.$mount();
document.body.appendChild(instance.$el);
// #endif
